package qky.api.controller.firm;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import qky.common.validator.ValidatorUtils;
import qky.api.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import qky.api.entity.BizUserFirmRoleEntity;
import qky.api.service.BizUserFirmRoleService;
import qky.common.utils.PageUtils;
import qky.common.utils.R;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;



/**
 * 用户公司关联表
 *
 * @author qky
 * @email qky_coding_man@gmail.com
 * @date 2022-01-15 00:08:48
 */
@RestController
@RequestMapping("api/firmauth")
@Api(tags="企业角色权限", description = "【未开放】")
public class ApiBizUserFirmRoleController extends BaseController {

    @Autowired
    private BizUserFirmRoleService bizUserFirmRoleService;

    @PostMapping("/page")
    @ApiOperation(value = "列表页面",notes = "分页列表，条件用类似search_EQ_id模式")
    public R page(@RequestParam Map<String, Object> params){
        PageUtils page = bizUserFirmRoleService.queryPage(buildPageParam(params));
        return R.ok().putData(page);
    }

    @PostMapping("/list")
    @ApiOperation(value = "列表",notes = "列表，条件用search_EQ_ID模式")
    public R list(@RequestParam Map<String, Object> params){
        List<BizUserFirmRoleEntity> list = bizUserFirmRoleService.queryList(buildPageParam(params));
        return R.ok().putData(list);
    }

    @PostMapping("/info/{firmId}")
    @ApiOperation(value = "详情",notes = "根据ID查询详情")
    public R info(@PathVariable("firmId") String firmId){
        BizUserFirmRoleEntity entity = bizUserFirmRoleService.query(firmId);
        return R.ok().putData(entity);
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存",notes = "保存")
    public R save(@RequestBody BizUserFirmRoleEntity bizUserFirmRole){
        bizUserFirmRoleService.save(bizUserFirmRole);
        return R.ok();
    }

    @PostMapping("/update")
    @ApiOperation(value = "更新",notes = "根据ID更新")
    public R update(@RequestBody BizUserFirmRoleEntity bizUserFirmRole){
        ValidatorUtils.validateEntity(bizUserFirmRole);
        bizUserFirmRoleService.update(bizUserFirmRole);
        return R.ok();
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除",notes = "根据ID删除，多个ID英文逗号拼接")
    public R delete(@RequestParam String firmIds){
        bizUserFirmRoleService.delete(Arrays.asList(firmIds.split(",")));
        return R.ok();
    }

}
